package exceptionexer;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入内容，输入exit结束");
        while (true){
            String line = scan.nextLine();
            if ("exit".equals(line)){
                System.out.println("退出成功");
                break;
            }
            pw.println(line);
        }
        pw.close();


//        PrintWriter pw = new PrintWriter("pw.txt");
//        pw.println("一二三四五");
//        pw.println("上山打老虎");
//        System.out.println("写出完毕");
//        pw.close();

//        FileOutputStream fos = new FileOutputStream("pw.txt");
//        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
//        BufferedWriter bw = new BufferedWriter(osw);
//        PrintWriter pw = new PrintWriter(bw,true);
//
//        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入内容，输入exit结束");
//        while (true){
//            String line = scan.nextLine();
//            if ("exit".equals(line)){
//                System.out.println("退出成功");
//                break;
//            }
//            pw.println(line);
//        }
//        pw.close();
    }
}
